package com.yyfax.pay.common.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 订单状态枚举
 * 
 * @author buyi
 * @date 2017-08-25 10:42:04
 * @since v2.1.5
 */
public enum OrderStateEnum {
	/** 初始化 */
	INI("0"),
	/** 成功 */
	SUCCESS("1"),
	/** 失败 */
	FAIL("2"),
	/** 处理中 */
	DEALING("3"),
	/** 已受理 */
	ACCEPTED("4"),
	/** 请求超时*/
	TIMEOUT("5"),
	/** 待确认*/
	TOCONFIRM("6");

	private String value;

	private OrderStateEnum(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean isValue(String value) {
		return StringUtils.equals(getValue(), value);
	}

	/**
	 * 转换文件服务器的状态为富友存管的状态码
	 * 
	 * @author buyi
	 * @date 2017-09-07 17:17:53
	 * @since v2.1.5
	 * @param fileServcerStateEnum
	 * @return
	 */
	public static OrderStateEnum parse(FileServcerStateEnum fileServcerStateEnum) {
		if (fileServcerStateEnum == FileServcerStateEnum.SUCCESS) {
			return OrderStateEnum.SUCCESS;
		} else if (fileServcerStateEnum == FileServcerStateEnum.FAIL) {
			return OrderStateEnum.FAIL;
		}

		return null;
	}

	public static OrderStateEnum from(String value){
		for(OrderStateEnum stateEnum : OrderStateEnum.values()){
			if(stateEnum.isValue(value)){
				return stateEnum;
			}
		}

		return null;
	}

	public static boolean isResult(String value) {
		if (OrderStateEnum.SUCCESS.getValue().equals(value) || OrderStateEnum.FAIL.getValue().equals(value)) {
			return true;
		}
		return false;
	}

}
